package com.skstudio.nuprint.lpd;

import java.text.DateFormat;
import java.util.Date;

public class LpdPrintJob {
	String mQueueName = null;
	
	public LpdPrintJob (String queueName) {
		mQueueName = queueName;
	}
	
	public class LpdControlFile {
		public String classForBannerPage;
		public String hostName;
		public String indentCount;
		public String jobNumber;
		public String userName;
		public String email;
		public String fileName;
		public String userId;
		public String symbolicLinkData;
		public String title;
		public String fileToUnlink;
		public String widthCount;
		public String troffRFontFileName;
		public String troffIFontName;
		public String troffBFontName;
		public String troffSFontName;
		public String plotCIFFileName;
		public String printDVIFileName;
		public String fileToPrintAsText;
		public String fileToPlot;
		public String fileToPrintAsTextRaw;
		public String fileToPrintAsDitroff;
		public String fileToPrintAsPostscript;
		public String fileToPrintAsPr;
		public String fileToPrintFortran;
		public String fileToPrintAsTroff;
		public String fileToPrintAsRaster;	
		
		public void write(StringBuilder sb) {
			sb.append("hostName          : " + hostName + "\r\n");
			sb.append("jobNumber         : " + jobNumber + "\r\n");
			sb.append("userName          : " + userName + "\r\n");
			sb.append("fileName          : " + fileName + "\r\n");
			sb.append("userId            : " + userId + "\r\n");
			sb.append("title             : " + title + "\r\n");
		}
		
		protected void setAttribute(String command, String operand)
		{
			if (command.equalsIgnoreCase("C"))
			{
				classForBannerPage = operand;
			}
			else if (command.equalsIgnoreCase("H"))
			{
				hostName = operand;
			}
			else if (command.equalsIgnoreCase("I"))
			{
				indentCount = operand;
			}
			else if (command.equalsIgnoreCase("J"))
			{
				jobNumber = operand;
			}
			else if (command.equalsIgnoreCase("L"))
			{
				userName = operand;
			}
			else if (command.equalsIgnoreCase("M"))
			{
				email = operand;
			}
			else if (command.equalsIgnoreCase("N"))
			{
				fileName = operand;
			}
			else if (command.equalsIgnoreCase("P"))
			{
				userId = operand;
			}
			else if (command.equalsIgnoreCase("S"))
			{
				symbolicLinkData = operand;
			}
			else if (command.equalsIgnoreCase("T"))
			{
				title = operand;
			}
			else if (command.equalsIgnoreCase("U"))
			{
				fileToUnlink = operand;
			}
			else if (command.equalsIgnoreCase("W"))
			{
				widthCount = operand;
			}
			else if (command.equalsIgnoreCase("1"))
			{
				troffRFontFileName = operand;
			}
			else if (command.equalsIgnoreCase("2"))
			{
				troffIFontName = operand;
			}
			else if (command.equalsIgnoreCase("3"))
			{
				troffBFontName = operand;
			}
			else if (command.equalsIgnoreCase("4"))
			{
				troffSFontName = operand;
			}
			else if (command.equalsIgnoreCase("c"))
			{
				plotCIFFileName = operand;
			}
			else if (command.equalsIgnoreCase("d"))
			{
				printDVIFileName = operand;
			}
			else if (command.equalsIgnoreCase("f"))
			{
				fileToPrintAsText = operand;
			}
			else if (command.equalsIgnoreCase("g"))
			{
				fileToPlot = operand;
			}
			else if (command.equalsIgnoreCase("l"))
			{
				fileToPrintAsTextRaw = operand;
			}
			else if (command.equalsIgnoreCase("n"))
			{
				fileToPrintAsDitroff = operand;
			}
			else if (command.equalsIgnoreCase("o"))
			{
				fileToPrintAsPostscript = operand;
			}
			else if (command.equalsIgnoreCase("p"))
			{
				fileToPrintAsPr = operand;
			}
			else if (command.equalsIgnoreCase("r"))
			{
				fileToPrintFortran = operand;
			}
			else if (command.equalsIgnoreCase("t"))
			{
				fileToPrintAsTroff = operand;
			}
			else if (command.equalsIgnoreCase("v"))
			{
				fileToPrintAsRaster = operand;
			}
		}
		
		public int size = 0;
		public byte[] contents;
		
		public void setControlFileCommands(byte[] ctrlFile) {
			contents = ctrlFile;
			
			String file = new String(contents);
			String[] commands = file.split("\n");
			for (String cmd : commands) {
				String[] opds = CommandHandler.parseOperands(cmd);
				setAttribute(cmd.substring(0, 1), opds[0]);
			}
		}
	}
	
	public class LpdDataFile {
		public int	size = 0;
		public String hostName;
		public String jobNumber;
		public byte[] contents;
		
		public void write(StringBuilder sb) {
			sb.append("hostName          : " + hostName + "\r\n");
			sb.append("jobNumber         : " + jobNumber + "\r\n");
			sb.append("time              : " + DateFormat.getDateInstance().format(new Date()) + "\r\n");
		}
	}
	
	LpdControlFile mCtrlFile = new LpdControlFile();
	LpdDataFile	mDataFile = new LpdDataFile();
	
	public LpdControlFile getCtrlFile() {
		return mCtrlFile;
	}
	
	public LpdDataFile getDataFile() {
		return mDataFile;
	}
	
	/// <summary>
	/// Job id default length
	/// </summary>
	public static int JOB_ID_LENGTH = 8;

	/// <summary>
	/// Job name default length
	/// </summary>
	public static int JOB_NAME_LENGTH = 20;

	/// <summary>
	/// Job owner default length
	/// </summary>
	public static int JOB_OWNER_LENGTH = 15;

	/// <summary>
	/// Job date default length
	/// </summary>
	public static int JOB_DATE_LENGTH = 20;

	/// <summary>
	/// Job size default length
	/// </summary>
	public static int JOB_SIZE_LENGTH = 9;
	
	public String getLongDescription() {
		return null;
	}

	public String getShortDescription() {
		return null;
	}
}
